//
//  HousesViewController.m
//  YJRenter
//
//  Created by 文彬 on 2018/7/2.
//  Copyright © 2018年 文彬. All rights reserved.
//

#import "HousesViewController.h"
#import "HouseInfoTableViewCell.h"
#import "HouseMoneyTableViewCell.h"
#import "HouseFilterView.h"
#import "HouseDetailViewController.h"

@interface HousesViewController ()<UITableViewDelegate,
    UITableViewDataSource>

@property (strong, nonatomic) UITableView *listTableView;
@property (strong, nonatomic) HouseFilterView *filterView;

@end

@implementation HousesViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navigationItem.title = @"时租";
    
    [self initPageControl];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

- (void)initPageControl{
    
    [self.view addSubview:self.filterView];
    
    [self.view addSubview:self.listTableView];
    [self.listTableView makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(@(self.filterView.frame.size.height));
        make.left.right.bottom.equalTo(@0);
    }];
}

#pragma mark UITableView
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 10;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return 2;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 10;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row==0) {
        return 200;
    }
    return 60;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if(indexPath.row==0){
        
        HouseInfoTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"HouseInfoTableViewCell" forIndexPath:indexPath];
        [cell.houseImgView sd_setImageWithURL:[NSURL URLWithString:@"https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=4036889747,3526425271&fm=27&gp=0.jpg"] placeholderImage:nil];
        [cell.headImgView setRoundImageWithURL:@"https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=4036889747,3526425271&fm=27&gp=0.jpg" placeholderImage:nil];
        return cell;
    }
    
    
    HouseMoneyTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"HouseMoneyTableViewCell" forIndexPath:indexPath];
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    HouseDetailViewController *detailController = [[HouseDetailViewController alloc]init];
    [self.navigationController pushViewController:detailController animated:YES];
}


#pragma mark getter
- (UITableView*)listTableView{
    if (_listTableView==nil) {
        _listTableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStyleGrouped];
        _listTableView.delegate = self;
        _listTableView.dataSource = self;
        _listTableView.sectionFooterHeight = 0;
        _listTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _listTableView.backgroundColor = [UIColor clearColor];
        _listTableView.separatorStyle = UITableViewCellSeparatorStyleNone;        [_listTableView registerNib:[UINib nibWithNibName:@"HouseMoneyTableViewCell" bundle:nil] forCellReuseIdentifier:@"HouseMoneyTableViewCell"];
        [_listTableView registerNib:[UINib nibWithNibName:@"HouseInfoTableViewCell" bundle:nil] forCellReuseIdentifier:@"HouseInfoTableViewCell"];
        
      
    }
    
    return _listTableView;
}

- (HouseFilterView*)filterView{
    if (_filterView==nil) {
        _filterView  = [[HouseFilterView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 45)];
    }
    return _filterView;
}
@end
